import 'package:flutter/material.dart';
import 'package:flutter_mode/utils.dart';
//import 'package:simple_permissions/simple_permissions.dart';


class PermissionPage3 extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _PermissionPage3State();
  }
}
class _PermissionPage3State extends State<PermissionPage3> {

  var listItems = {};

  /// 加载权限信息
  _loadPemissionInfo() async {

    /*var permissionItems = {
      '相机': Permission.Camera,
      '内存': Permission.ReadExternalStorage,
      '位置': Permission.AlwaysLocation,
    };

    for(var entry in permissionItems.entries) {
      //checkPermission结果简单
      var result = await SimplePermissions.getPermissionStatus(entry.value);
      listItems['${entry.key}(${_resolvPermission(result)})'] = () => _requestPermission(entry.value, entry.key);
    }*/

  }

  /// 请求权限
  /*_requestPermission(Permission permission, String name) async {
    var result = await SimplePermissions.requestPermission(permission);

    showAlert(context, '请求权限$name,得到状态${_resolvPermission(result)}');

    setState(() {});
  }*/

  /// 权限状态
  /*String _resolvPermission(PermissionStatus permissionStatus) {
    switch (permissionStatus) {
      case PermissionStatus.notDetermined:
        return 'notDetermined';
      case PermissionStatus.restricted:
        return 'restricted';
      case PermissionStatus.denied:
        return 'denied';
      case PermissionStatus.authorized:
        return 'authorized';
      case PermissionStatus.deniedNeverAsk:
        return 'deniedNeverAsk';
      default:
        return 'unKnown';
    }
  }*/

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return Scaffold(
      appBar: AppBar(
        title: Text('PermissionDemo'),
        actions: <Widget>[
          IconButton(
              icon: Icon(Icons.settings),
              onPressed: () => {/*SimplePermissions.openSettings()*/})
        ],
      ),
      body: FutureBuilder(
          future: _loadPemissionInfo(),
          builder: (context, snapshot) {
            return ListView.separated(
              itemBuilder: (context, position) {
                var item = listItems.entries.elementAt(position);
                return ListTile(
                  title: Text(item.key),
                  onTap: item.value,
                );
              },
              itemCount: listItems.length,
              separatorBuilder: (context, position) => Divider(
                height: 1,
              ),
            );
          }),
    );
  }
}